package com.lujianfei.imagesearch.widget;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.List;

import javax.swing.JPanel;

import com.lujianfei.imagesearch.utils.MnistReader;
import com.lujianfei.imagesearch.utils.MnistReader.MnistInfo;

public class MnistImageView extends JPanel {

	private List<BufferedImage> bufferedImages;
	private MnistReader mnistReader = new MnistReader();
	private int width,height;
	public MnistImageView() {
		super();
		setOpaque(false);
	}

	
	public void setImage(String filepath,MnistInfo info) {
		this.bufferedImages = mnistReader.getBufferedImages(filepath,info);
		width = info.width;
		height = info.height;
		repaint();
	}


	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		if (bufferedImages != null && !bufferedImages.isEmpty()) {
			for (int i = 0; i < bufferedImages.size(); i++) {
				g.drawImage(bufferedImages.get(i), 0, i * height, width, height, null);
			}
		}
	}
	
	void log(String text) {
		System.out.println("MnistImageView:"+text);
	}
}
